<?php
require_once('../models/Model.php');

class Content extends Model{

    public function getAll(){
        $sql = "select c.*,u.username from blog_content as c
left join blog_user as u on c.user_id = u.id";

        $mysql = $this->getMysql();

        $arr = $mysql->GetAll($sql);

        $mysql->close_connect();

        return $arr;
    }

    public function getOne($id){
        $sql = "select c.*,u.username from blog_content as c
left join blog_user as u on c.user_id = u.id where c.id=".$id;

        $mysql = $this->getMysql();

        $arr = $mysql->GetAssoc($sql);

        $mysql->close_connect();

        return $arr[0];
    }

    //创建blog文章
    public function create($data)
    {
        $mysql = $this->getMysql();

        $table = 'blog_content';

        $id =  $mysql->Insert($table,$data);

        $mysql->close_connect();

        return $id;
    }

}

